<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
        <div class="table-handle">
          <el-button type="primary" size="mini" icon="el-icon-plus" @click="onAdd">新增</el-button>
        </div>
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              row-key="id"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column prop="id" label="ID" width="60"/>
            <el-table-column prop="travel_id" label="旅游产品ID" width="100"/>
            <el-table-column prop="travel_sku_id" label="SKU ID" width="100"/>
            <el-table-column prop="user_id" label="用户ID" width="100"/>
            <el-table-column prop="distributor_id" label="分销员ID" width="100"/>
            <el-table-column prop="prepay_amount" label="预付金额" width="120">
              <template slot-scope="scope">
                <span style="color: #E6A23C; font-weight: bold;">¥{{ scope.row.prepay_amount }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="share_amount" label="分销佣金" width="120">
              <template slot-scope="scope">
                <span style="color: #67C23A; font-weight: bold;">¥{{ scope.row.share_amount }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="120">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.status === 'pending'" type="warning">待支付</el-tag>
                <el-tag v-if="scope.row.status === 'paid'" type="success">已支付</el-tag>
                <el-tag v-if="scope.row.status === 'refunding'" type="danger">退款中</el-tag>
                <el-tag v-if="scope.row.status === 'confirmed'" type="primary">已确认</el-tag>
                <el-tag v-if="scope.row.status === 'refunded'" type="info">已退款</el-tag>
                <el-tag v-if="scope.row.status === 'completed'" type="success">已完成</el-tag>
                <el-tag v-if="scope.row.status === 'cancelled'" type="danger">已取消</el-tag>
                <el-tag v-if="scope.row.status === 'pending_verification'" type="warning">待确认</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="qrcode" label="分销二维码" width="120">
              <template slot-scope="scope">
                <el-image
                    v-if="scope.row.qrcode"
                    :preview-src-list="[scope.row.qrcode]"
                    style="width: 60px; height: 60px"
                    :src="scope.row.qrcode" fit="contain">
                </el-image>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column prop="share_image_url" label="分销海报" width="120">
              <template slot-scope="scope">
                <el-image
                    v-if="scope.row.share_image_url"
                    :preview-src-list="[scope.row.share_image_url]"
                    style="width: 60px; height: 60px"
                    :src="scope.row.share_image_url" fit="contain">
                </el-image>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column prop="creator" label="创建者" width="100"/>
            <el-table-column prop="create_time" label="创建时间" width="160">
              <template slot-scope="scope">
                {{ scope.row.create_time | parseTime }}
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="200">
              <template slot-scope="scope">
                <el-button type="text" @click="onEdit(scope.row)">编辑</el-button>
                <el-button type="text" @click="onDetail(scope.row)">详情</el-button>
                <el-button type="text" style="color: #F82222" @click="onDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
      <div class="page-box">
        <el-pagination
            background
            :current-page="pageNo"
            :page-sizes="pageSizes"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalSize"
            @size-change="changePageSize"
            @current-change="changePageNo"
        />
      </div>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";

export default {
  name: "TravelShareOrderIndex",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: http.travelShareOrder,
      searchList: [
        {
          type: 'input',
          label: '旅游产品ID',
          prop: 'travel_id',
          placeholder: '请输入旅游产品ID'
        },
        {
          type: 'input',
          label: '用户ID',
          prop: 'user_id',
          placeholder: '请输入用户ID'
        },
        {
          type: 'input',
          label: '分销员ID',
          prop: 'distributor_id',
          placeholder: '请输入分销员ID'
        },
        {
          type: 'select',
          label: '状态',
          prop: 'status',
          placeholder: '请选择状态',
          options: [
            { label: '待支付', value: 'pending' },
            { label: '已支付', value: 'paid' },
            { label: '退款中', value: 'refunding' },
            { label: '已确认', value: 'confirmed' },
            { label: '已退款', value: 'refunded' },
            { label: '已完成', value: 'completed' },
            { label: '已取消', value: 'cancelled' },
            { label: '待确认', value: 'pending_verification' }
          ]
        }
      ],
      searchParams: {
        travel_id: '',
        user_id: '',
        distributor_id: '',
        status: ''
      },
      defaultParams: {
      },
      tableData: []
    }
  },
  methods: {
    onDetail(row) {
      this.$router.push({
        path: '/travelShareOrder/detail',
        query: { id: row.id }
      });
    }
  }
}
</script>

<style scoped lang="scss">
.table-layout {
  margin-top: 20px;
}
.table-handle {
  margin-bottom: 20px;
}
.page-box {
  margin-top: 20px;
  text-align: right;
}
</style>
